package com.store.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.store.app.R;

/**
 * Created by Administrator on 2015/10/21.
 */
public class CouponGoCashAdapter extends BaseAdapter {



    private int count=-1;
    private Context context;
    private String[] data;

    public CouponGoCashAdapter( Context context,String[] data) {
        this.context = context;
        this.data=data;
    }
    public void setCount(int count){
        this.count=count;
    }
    @Override
    public int getCount() {
        return data.length;
    }

    @Override
    public String getItem(int position) {
        return data[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if(convertView == null)
        {

            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_coupongocash,null);
            holder.tvName = (TextView) convertView.findViewById(R.id.tv_coupon);

            convertView.setTag(holder);

        }else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvName.setText(data[position] );
        if(count==position) {
            holder.tvName.setBackgroundResource(R.drawable.scalefun_2);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.white));
        }else{
            holder.tvName.setBackgroundResource(R.drawable.coupongocash);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.main_color_blue));
        }
        return convertView;
    }


    class ViewHolder
    {
        private ImageView ivPhoto;
        private TextView tvName;
    }
}
